<template>
    <table-view :show-block-control="false">
        <template slot="formSlot">
            <el-form ref="form" :model="form" label-width="80px" :inline="true">
                <el-form-item label="菜单" prop="name">
                    <el-input v-model="form.name" size="small"></el-input>
                </el-form-item>
            </el-form>
        </template>

        <div slot="btnBeforeSlot">
            <el-button type="info" plain icon="el-icon-document-add" size="small" @click="handleAdd">新增</el-button>
        </div>
        <div slot = "btnAfterSlot">
            <el-button type="info" plain icon="el-icon-search" size="small" @click="handleSearch">查询</el-button>
            <el-button type="info" plain icon="el-icon-s-release" size="small" @click="handleRest">重置</el-button>
        </div>

        <template slot="tableSlot">
            <el-table v-loading="loading" :data="tableData" stripe height="100%" size="small" row-key="id"
                      width="100%" :tree-props="{children: 'children'}">
                <el-table-column prop="code" label="菜单编码" width="220"></el-table-column>
                <el-table-column prop="name" label="菜单名" width="220"></el-table-column>
                <el-table-column prop="path" label="菜单url" width="200"></el-table-column>
                <el-table-column prop="icon" label="菜单样式" width="180"></el-table-column>
                <el-table-column prop="enabled" label="状态" width="180">
                    <template slot-scope="scope">
                        <el-switch
                            v-model="scope.row.enabled"
                            active-color="#13ce66"
                            inactive-color="#ff4949"
                            :active-value="+enableds[0].value"
                            :inactive-value.number="+enableds[1].value"
                            @change="handleChange($event,scope.row)">
                        </el-switch>
                    </template>
                </el-table-column>
                <el-table-column prop="sort" label="排序" width="80"></el-table-column>
                <el-table-column prop="createTime" label="创建时间"></el-table-column>
                <el-table-column prop="updateTime" label="更新时间"></el-table-column>
                <el-table-column label="操作" fixed="right"  width="200" align="center">
                    <template slot-scope="scope">
                        <el-tooltip class="item" effect="dark" content="编辑" placement="top-start">
                            <el-button type="primary" plain size="mini"icon="el-icon-edit"
                                       @click="handleAdd(scope.row)" class="tableBtn"></el-button>
                        </el-tooltip>
                        <el-tooltip class="item" effect="dark" content="删除" placement="top-start">
                            <el-button type="danger" plain size="mini" icon="el-icon-delete"
                                       @click="handleDel(scope.row)" class="tableBtn"></el-button>
                        </el-tooltip>
                        <el-tooltip class="item" effect="dark" content="查看" placement="top-start">
                            <el-button type="info" plain size="mini"  icon="el-icon-search"
                                       @click="handleDetail(scope.row)" class="tableBtn"></el-button>
                        </el-tooltip>
                    </template>
                </el-table-column>
            </el-table>
        </template>


        <template slot="otherSlot">
            <dialog-view ref="dialogRef" :title="dialogParams.title" :width="dialogParams.width">
                <template slot="dialogSlot">
                    <component :is="dialogParams.componentName" :editData="editRow"
                               @submitSuccess="handleSearch"></component>
                </template>
            </dialog-view>
        </template>
    </table-view>
</template>

<script>
    import TableView from '@/components/tableView'
    import DialogView from '@/components/dialogView'
    import tableMixin from '@/mixins/table.mixin'
    import {mapState, mapActions} from 'vuex'
    export default {
        mixins: [tableMixin],
        data() {
            return{
                searchApi: this.$api.system.menu.list,
                deleteApi: this.$api.system.menu.delete,
                form: {
                    name: ''
                }
            }
        },
        components: {
            TableView,
            DialogView,
            Add: () => import('./add'),
            Detail: () => import('./detail')
        },
        computed: {
            ...mapState('dic', ['enableds'])
        },
        methods: {
            ...mapActions('dic', ['doEnabledOfBasic']),
            handleChange(status,val) {
                val.enabled = status;
                this.$ajax.post(this.$api.system.menu.editEnable,val).then(result=>{
                    this.handleSearch();
                });
            }
        },
        mounted() {
            this.doEnabledOfBasic();
            // this.doMenus();
        }
    }
</script>

<style scoped lang="less">
    @import "../../../assets/css/common.less";
</style>
